#include "Log.h"

namespace logging {

Log::Log(LogOutput *output, char* ns, Level level)
	: _output(output) {
	int len = strlen(ns);
	_namespace = new char[len+1];
	strncpy(_namespace, ns, len+1);
	setLevel(level);
}

Log::~Log() {
	delete[] _namespace;
}

Logger Log::debug() {
	return Logger(_output, _namespace, getLevel(), log_debug);
}

Logger Log::info() {
	return Logger(_output, _namespace, getLevel(), log_info);
}

Logger Log::warn() {
	return Logger(_output, _namespace, getLevel(), log_warn);
}

Logger Log::error() {
	return Logger(_output, _namespace, getLevel(), log_error);
}

Logger Log::fatal() {
	return Logger(_output, _namespace, getLevel(), log_fatal);
}

Level Log::getLevel() {
	_lock.readLock();
	Level level = _level;
	_lock.unlock();
	return level;
}

void Log::setLevel(Level level) {
	_lock.writeLock();
	_level = level;
	_lock.unlock();
}

}
